package com.ruoyi.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.HospitalDepartment;
import com.ruoyi.hospital.service.IHospitalDepartmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医院科室关联Controller
 * 
 * @author 天天困
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/hospital/hospitaldepartment")
public class HospitalDepartmentController extends BaseController
{
    @Autowired
    private IHospitalDepartmentService hospitalDepartmentService;

    /**
     * 查询医院科室关联列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitaldepartment:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalDepartment hospitalDepartment)
    {
        startPage();
        List<HospitalDepartment> list = hospitalDepartmentService.selectHospitalDepartmentList(hospitalDepartment);
        return getDataTable(list);
    }

    /**
     * 导出医院科室关联列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitaldepartment:export')")
    @Log(title = "医院科室关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalDepartment hospitalDepartment)
    {
        List<HospitalDepartment> list = hospitalDepartmentService.selectHospitalDepartmentList(hospitalDepartment);
        ExcelUtil<HospitalDepartment> util = new ExcelUtil<HospitalDepartment>(HospitalDepartment.class);
        util.exportExcel(response, list, "医院科室关联数据");
    }

    /**
     * 获取医院科室关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitaldepartment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hospitalDepartmentService.selectHospitalDepartmentById(id));
    }

    /**
     * 新增医院科室关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitaldepartment:add')")
    @Log(title = "医院科室关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalDepartment hospitalDepartment)
    {
        return toAjax(hospitalDepartmentService.insertHospitalDepartment(hospitalDepartment));
    }

    /**
     * 修改医院科室关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitaldepartment:edit')")
    @Log(title = "医院科室关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalDepartment hospitalDepartment)
    {
        return toAjax(hospitalDepartmentService.updateHospitalDepartment(hospitalDepartment));
    }

    /**
     * 删除医院科室关联
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitaldepartment:remove')")
    @Log(title = "医院科室关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hospitalDepartmentService.deleteHospitalDepartmentByIds(ids));
    }
}
